<%@page import="com.realjinge.api.util.JsSignUtil"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
	+ request.getServerName() + ":" + request.getServerPort()
	+ path + "/";
	//动态获取url地址
	String url = request.getScheme()+"://"+ request.getServerName()+request.getRequestURI()+"?"+request.getQueryString();
	System.out.println(url);
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>控制面板</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<meta name="viewport"
	content="width=device-width,minimum-scale=1.0, maximum-scale=1.0" />
<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
<script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
<script type="text/javascript">
	
	<%Map<String, String> ret = new HashMap<String, String>();
		ret = JsSignUtil.sign(url);%> 
			
    wx.config({  
        debug: false,  
        appId: '<%=ret.get("appId")%>',  
        timestamp:'<%=ret.get("timestamp")%>',  
        nonceStr:'<%=ret.get("nonceStr")%>',  
        signature:'<%=ret.get("signature")%>',
		jsApiList : [ 'checkJsApi', 'scanQRCode' ]
	});//end_config  

	wx
			.ready(function() {

				wx.checkJsApi({
					jsApiList : [ 'scanQRCode' ],
					success : function(res) {
					}
				});

				//扫描二维码  
				document.querySelector('#scanQRCode').onclick = function() {

					wx
							.scanQRCode({
								needResult : 0, // 默认为0，扫描结果由微信处理，1则直接返回扫描结果，  
								scanType : [ "qrCode", "barCode" ], // 可以指定扫二维码还是一维码，默认二者都有  
								success : function(res) {
									var result = res.resultStr; // 当needResult 为 1 时，扫码返回的结果  
									document.getElementById("wm_id").value = result;//将扫描的结果赋予到jsp对应值上  
									alert("扫描成功！扫描码=" + result);

									// 定义ajax变量xmlhttp  
									var xmlhttp;

									// 创建xmlhttp  
									if (window.XMLHttpRequest) {
										xmlhttp = new XMLHttpRequest;
									} else {
										xmlhttp = new ActiveObject(
												"Microsoft.XMLHTTP");
									}
									// 拼接请求URL
									var url = "http://realjinge.ngrok.cc/wechat/callback.do?value="
											+ result;
									xmlhttp.open("get", url);
									xmlhttp.send();
<%String msg = request.getParameter("wm_id");
					System.out.println(msg);%>
	}

							});
				};//end_document_scanQRCode  

			});//end_ready

	wx.error(function(res) {
		alert("出错了：" + res.errMsg);
	});//end_error
</script>

<script type="text/javascript">
	function toCount() {
		//alert("count");
		window.location.href = "count.jsp? backurl=" + window.location.href;
	}
</script>
</head>

<body style="background: #5B9BD5;">
	<hr />
	<hr />
	<div style="text-align: center;">
		<button id="scanQRCode" style="background: #FFC000;">
			<h1 style="color: white;">扫一扫奶粉</h1>
		</button>
		<br> <input type="text" id="wm_id" name="vm_id">
	</div>
	<hr />
	<hr />
	<br>
	<div style="margin:0 auto;">
		<table style="margin:0 auto;text-align: center;" border="50"
			bordercolor="#4B8BD5">
			<tr>
				<td>
					<button style="background: #FFC000;">
						<h2 style="color: white;">水量调节</h2>
					</button>
				</td>
				<td>
					<button style="background: #FFC000;">
						<h2 style="color: white;">水温调节</h2>
					</button></td>
			</tr>
			<tr>
				<td colspan="2">
					<button style="background: #FFC000;">
						<h1 style="color: white;">一键冲奶</h1>
					</button></td>
			</tr>
			<tr>
				<td>
					<button style="background: #FFC000;">
						<h2 style="color: white;">高温清洗</h2>
					</button></td>
				<td>
					<button style="background: #FFC000;">
						<h2 style="color: white;">保温功能</h2>
					</button></td>
			</tr>
			<tr>
				<td>
					<button style="background: #70AD47;">
						<h1 style="color: white;">功能</h1>
					</button></td>
				<td>
					<button style="background: #FFC000;" onclick="toCount()">
						<h1 style="color: white;">统计</h1>
					</button></td>
			</tr>
		</table>
	</div>

</body>
</html>
